<?php
header('content-type:text/html;charset=UTF-8');

@$pageNo = $_REQUEST['pageNo'];

if (empty($pageNo)||!is_numeric($pageNo)||$pageNo<1){
	$pageNo = 1;
}

$pageSizet = 5;

$offset = ($pageNo-1)*$pageSizet;

require 'lib/db.php';

@$itemCount = dbSelect('select count(1) as x from list');

$pageCount = ceil($itemCount['x']/$pageSizet);


@$lists = dbSelectAll("select id,name,img,price from list order by id asc limit $offset,$pageSizet");
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<script type="text/javascript" src="query/jquery-1.11.1.min.js"></script>
<script type="text/javascript">
	
</script>
<style type="text/css">
	table,div{width:250px;margin:auto;text-align:center}
	table,th,td{border:solid 1px;margin:auto;border-collapse:collapse}
	th{background:#cbaf76;}
	td{background:#eadfc8;}
	div{padding-bottom:5px}
</style>
	</head>
	<body>
	<div>
		<a href="?pageNo=1">首页</a>
		<?php if($pageNo<=1){?>
			上一页
		<?php }else{?>
			<a href="?pageNo=<?php echo $pageNo-1; ?>">上一页</a>
		<?php }?>
		
		<?php if($pageNo>=$pageCount){?>
			下一页
		<?php }else{?>
			<a href="?pageNo=<?php echo $pageNo+1; ?>">下一页</a>
		<?php }?>
		<a href="?pageNo=<?php echo $pageCount; ?>">末页</a>
	</div>
		<table>
			<tr>
				<th>ID</th>
				<th>菜名</th>
				<th>图片</th>
				<th>单价</th>
			</tr>
				<?php  foreach($lists as $list){?>
			<tr>
				<td><?php  echo $list['id']; ?></td>
				<td><?php  echo $list['name']; ?></td>
				<td><?php  echo $list['img']; ?></td>
				<td><?php  echo $list['price']; ?></td>
			</tr>
			<?php }?>
		</table>
	
	</body>
</html>